<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*,java.util.*"  %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 <jsp:useBean id="query" scope="session" class="dataconn.MyDbBean"/>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>插入数据</title>
   </head>
   <body>
       <%!	String xuehao,name,sex,age,jiguan,department,url,sql; %>
       <%! int i;%>      
       <%
          xuehao=request.getParameter("xuehao").trim();
          name=request.getParameter("name").trim();
          name=new String(name.getBytes("ISO-8859-1"),"UTF-8");//编码转换
          sex=request.getParameter("sex").trim();
          sex=new String(sex.getBytes("ISO-8859-1"),"UTF-8");
          age=request.getParameter("age").trim();
          i=Integer.parseInt(age);
          jiguan=request.getParameter("jiguan").trim();
          jiguan=new String(jiguan.getBytes("ISO-8859-1"),"UTF-8");
          department=request.getParameter("department").trim();
          department=new String(department.getBytes("ISO-8859-1"),"UTF-8");
          if(xuehao.length()!=7){//检查学号的位数
              response.sendRedirect("err.jsp");
          }
          if(name.equals("")){//检查姓名是否为空
              response.sendRedirect("err.jsp");
          }
          //调用getConn()方法与数据库建立连接
          query.getConn("Data_Stu","sa","");
          sql="select * from stuInfo where 学号='"+xuehao+"'";
          ResultSet  rs=query.executeQuery1(sql);
          if(rs.getRow()>0)
          {     response.sendRedirect("err.jsp");   }
          sql="insert into stuInfo(学号,姓名,性别,年龄,籍贯,院系)";
          sql=sql+"values('"+xuehao+"','"+name+"','"+sex+"','"+i+"','"+jiguan+"','"+department+"')";
          query.executeUpdate2(sql);
          out.println("<font size=3 color=blue>正在处理信息，请稍后......</font><meta http-equiv='refresh' content='2;url=list.jsp'>");
          rs.close();
          query.closeStmt();
          query.closeConn();
        %>
     </body>
</html>
